﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using OpenPowerPoint.Collection;

namespace OpenPowerPointTest.Collections
{
    /// <summary>
    /// Tests the functionallity of the used code for WinForms property setting/resetting and WPF equivalent
    /// </summary>
    [TestFixture]
    [Category("Unit: Notifyable List")]
    public class NotifyableItem
    {
        private NotifierClass _baseItem;

        #region Setup/Teardown
        [SetUp]
        public void Setup()
        {
            _baseItem = new NotifierClass() { Caption = "caption"};
        }

        [TearDown]
        public void TearDown()
        { }
        #endregion

        #region WPF Tests
        /// <summary>
        /// Tests whether the event gets raised by WPF
        /// </summary>
        [Test]
        public void WpfPropertyEvent()
        {
            bool raised = false;

            _baseItem.PropertyChanged += (o, e) => raised = true;
            _baseItem.Caption = "WpfPropertyEvent";

            Assert.That(raised, Is.EqualTo(true), "Event not rissen by Depenedy Property");
        }

        /// <summary>
        /// Tests whether the value is changeable in WPF
        /// </summary>
        [Test]
        public void WpfChangeValue()
        {
            _baseItem.Caption = "WpfChangeValue";

            Assert.AreEqual("WpfChangeValue", _baseItem.Caption, "Cannot set WPF Property");
        }

        /// <summary>
        /// Tests whether the value can be reset via NewValue argument in WPF
        /// </summary>
        [Test]
        public void WpfResetValue()
        {
            _baseItem.Caption = "before";
            _baseItem.PropertyChanged += (o, e) => e.NewValue = "WpfResetValue";
            _baseItem.Caption = "after";

            Assert.AreEqual("WpfResetValue", _baseItem.Caption, "Cannot reset WPF Property via NewValue=OldValue");
        }
        #endregion
    }
}
